home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Applications / Alpha.5.81 folder / xtcls / example2.c < prev    next >
C/C++ Source or Header  |  1994-07-28  |  2KB  |  103 lines

  1. #include    "xtcl.h"
  2. #include    <sound.h>
  3.  
  4. #define    STR_LEN        80
  5.  
  6. /*
  7.  * Think C 5.04 - be sure to link w/ an A4-based version of the ANSI library.
  8.  * The following routine uses the callback function to create an Alpha menu 
  9.  * whose items call back into this XTCL...
  10.  *
  11.  * The Alpha menu contains a list of sounds that can by played back .
  12.  *
  13.  * This rsrc *must* be loaded into Alpha's resource fork so that it
  14.  * can be found when called from the menu. Alpha currently (5.3) *is* 
  15.  * distributed w/ this resource installed. To try it out, merely go to
  16.  * the Tcl shell and type "xtclcmd sounds init".
  17.  */
  18. void
  19. main(argc, argv, xpb)
  20. long        argc;
  21. char        **argv;
  22. XTCLParmBlk    *xpb;
  23. {
  24.     char    *ptr, *errString;
  25.     long    i;
  26.     Handle    sHandle;
  27.     
  28.     if (argc < 2)
  29.     {
  30.       usage:
  31.         errString = "Usage: sounds init\r       sounds beep <sound-name>\r       sounds beep Remove";
  32.         SetHandleSize(xpb->resultH, (long)STR_LEN);
  33.         strncpy(*xpb->resultH, errString, (long)STR_LEN);
  34.         (*xpb->resultH)[STR_LEN - 1] = 0;
  35.         xpb->result = TCL_ERROR;
  36.         return;
  37.     }
  38.     
  39.     xpb->result = TCL_OK;
  40.     sHandle = NewHandle(500);
  41.     HLock(sHandle);
  42.     
  43.     if (!strcmp(argv[1], "init"))
  44.     {
  45.         ResType        type;
  46.         int            i, num;
  47.         char        *ptr = *sHandle;
  48.         
  49.         strcpy(ptr, "menu -n Sounds -m -p playSound {\r");
  50.  
  51.         num = CountResources('snd ');
  52.         for (i = 1; i <= num; i++)
  53.         {
  54.             Handle    rsrc;
  55.             short    id;
  56.             ResType    dummyType;
  57.             char    name[STR_LEN];
  58.             
  59.             rsrc = GetIndResource('snd ', i);
  60.             GetResInfo(rsrc, &id, &dummyType, name);
  61.             name[name[0] + 1] = 0;
  62.             strcat(ptr, "\"");
  63.             strcat(ptr, name + 1);
  64.             strcat(ptr, "\" ");
  65.             ReleaseResource(rsrc);
  66.         }
  67.         strcat(ptr, "\"(-\" \"Remove\"}\r");
  68.         strcat(ptr, "proc playSound {menu name} {xtclcmd Sounds beep \"$name\"}\r");
  69.         strcat(ptr, "insertMenu Sounds\r");
  70.         (* xpb->eval)(xpb, sHandle, NULL, NULL);
  71.     }
  72.     else if (!strcmp("beep", argv[1]))
  73.     {
  74.         Handle        snd;
  75.         char        temp[STR_LEN];
  76.         
  77.         if (argc != 3)  goto usage;
  78.         if (!strcmp(argv[2], "Remove"))
  79.         {
  80.             strcpy(*sHandle, "removeMenu Sounds\r");
  81.             (* xpb->eval)(xpb, sHandle, NULL, NULL);
  82.         }
  83.         else
  84.         {
  85.             strcpy(temp + 1, argv[2]);
  86.             temp[0] = strlen(temp + 1);
  87.             if (!(snd = GetNamedResource('snd ', temp))) goto usage;
  88.             SndPlay((long)NULL, snd, FALSE);
  89.             ReleaseResource(snd);
  90.         }
  91.     }
  92.     else
  93.     {
  94.         HUnlock(sHandle);
  95.         DisposHandle(sHandle);
  96.         goto usage;
  97.     }
  98.     HUnlock(sHandle);
  99.     DisposHandle(sHandle);
  100. }
  101.  
  102.  
  103.